﻿using System.Collections.Generic;
using SpotOffer.AppConstants;
using SpotOffer.DataModels;
using SpotOffer.Resource;
using SpotOffer.View;
using Xamarin.Forms;

namespace SpotOffer.ViewModels
{
    public class SettingsViewModel : BaseViewModel
    {
        public List<SettingsItem> OpenDealList
        {
            get { return _openDealList; }
            set { _openDealList = value; NotifyPropertyChanged(); }
        }
        private List<SettingsItem> _openDealList;

        public List<SettingsItem> PictureSizeList
        {
            get { return _pictureSizeList; }
            set { _pictureSizeList = value; NotifyPropertyChanged(); }
        }
        private List<SettingsItem> _pictureSizeList;

        public SettingsItem SelectedOpenSetting
        {
            get{return _selectedOpenSetting;}
            set
            {
                if (value != null)
                {
                    //----------------------Styling---------------//
                    _openDealList[0].Higlighted = false;
                    _openDealList[1].Higlighted = false;

                    _selectedOpenSetting = value;
                    _selectedOpenSetting.Higlighted = true;
                    //----------------------Styling---------------//
                    _selectedOpenSetting = value;
                    App.Cache.Set(CacheKeys.Settings, _selectedOpenSetting.setting);
                }
            }
        }
        private SettingsItem _selectedOpenSetting;

        public SettingsItem SelectedPictureSizeSetting
        {
            get { return _selectedPictureSizeSetting; }
            set
            {
                if (value != null)
                {
                    //----------------------Styling---------------//
                    _pictureSizeList[0].Higlighted = false;
                    _pictureSizeList[1].Higlighted = false;

                    _selectedPictureSizeSetting = value;
                    _selectedPictureSizeSetting.Higlighted = true;
                    //----------------------Styling---------------


                    _selectedPictureSizeSetting = value;
                    App.Cache.Set(CacheKeys.PictureSettings, _selectedPictureSizeSetting.setting);
                    MessagingCenter.Send(this,MessagingConstants.RefreshDealList);
                }
            }
        }
        private SettingsItem _selectedPictureSizeSetting;

        public string Title { get { return AppResources.Settings; }}

        public override void OnViewAppearing()
        {
            base.OnViewAppearing();
          /*  if (App.AppInstance.MasterPageSpotOffer != null)
            {
                App.AppInstance.MasterPageSpotOffer.IsPresented = false;
            }*/

            var Internal = new SettingsItem { text = AppResources.InternBrowser, setting = CacheKeys.Internal };
            var External = new SettingsItem { text = AppResources.OpenDealExternally, setting = CacheKeys.External };
            if (App.Cache.Get<string>(CacheKeys.Settings).Equals(CacheKeys.Internal))
            {
                Internal.Higlighted = true;
                External.Higlighted = false;
            }
            else
            {
                Internal.Higlighted = false;
                External.Higlighted = true;
            }
            OpenDealList = new List<SettingsItem> { Internal, External };


            var Small = new SettingsItem { text = AppResources.PictureSmall, setting = CacheKeys.PicSmall };
            var Big = new SettingsItem { text = AppResources.PictureBig, setting = CacheKeys.PicBig };
            if (App.Cache.Get<string>(CacheKeys.PictureSettings).Equals(CacheKeys.PicBig))
            {
                Big.Higlighted = true;
                Small.Higlighted = false;
            }
            else
            {
                Big.Higlighted = false;
                Small.Higlighted = true;
            }
            PictureSizeList = new List<SettingsItem> { Big, Small };

        }

        public string TitleOpenDeal
        {
            get {return AppResources.OpenDeal;}
        }

        public string TitlePictureSize
        {

            get { return AppResources.DealPicture; }
        }



    }
}
